package rip.protocol;

import java.util.List;
import java.util.Timer;

import rip.threads.Sender;
import rip.threads.Updater;

public class NetTimer extends Timer {

	private static Timer timer = null;
	
	public static void start(){
		SendTask tt = new SendTask();
		timer = new Timer();
		timer.schedule(tt, 0);
		long l = tt.scheduledExecutionTime();
		System.out.println(l);
	}

	public static void main(String[] args) {
		ALGraph web = new ALGraph();
		web.initGraph();
		web.initRoutTables();
		
		Router router = web.getVertices().get(5).getRouter();
		List<RoutTableItem> routTable = router.getRoutTable();
		for (int i = 0; i < routTable.size(); i++) {
			System.out.print(routTable.get(i).getTargetNetwork().getAddress());
			System.out.print("  ");
			System.out.print(routTable.get(i).getDistance());
			System.out.print("  ");
			System.out.println(routTable.get(i).getNextRouter().getName());
		}
		
		Router r[] = new Router[6];
		for (int i = 0; i < web.getVertexNum(); i++ ){
			r[i] = web.getVertices().get(i).getRouter();
			System.out.print(r[i].getName() + "  ");
		}
		Thread send[] = new Thread[6];
		Thread update[] = new Thread[6];
		for (int i = 0; i < web.getVertexNum(); i++) {
			send[i] = new Thread(new Sender(r[i]), "sender" + i);
			update[i] = new Thread(new Updater(r[i]), "updater" + i);
		}
		for (int i =0; i< web.getVertexNum(); i++ ){
			send[i].start();update[i].start();
			
		}
		/*
		List<Network> neighbournetworks = web
				.getAllNeighbourArcNetwork(new Router(null, "F"));
		System.out.println(neighbournetworks.size());
		for (int i = 0; i < neighbournetworks.size(); i++) {
			System.out.println(neighbournetworks.get(i).getAddress());
		}
		List<Router> neighbourrouters = web
		.getAllNeighbourVexRouter(new Router(null, "F"));
		System.out.println(neighbourrouters.size());
		for (int i = 0; i < neighbourrouters.size(); i++) {
			System.out.println(neighbourrouters.get(i).getName());
		}

		*/
	}
}

class SendTask extends java.util.TimerTask{

	private Router router = null;

	public SendTask() {
		this(null);
	}

	public SendTask(Router router) {
		this.router = router;
	}

	@Override
	public void run() {
		while(true){
			System.out.println("Timer is running......");
		}
	}
	
}
